package com.pai4j.log.config;

import com.pai4j.log.aspect.LogAspect;
import com.pai4j.log.service.ILogService;
import com.pai4j.log.service.impl.LogServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;

/**
 * 日志模块自动配置类
 *
 * @author: CYM-pai
 * @date: 2025/07/29 16:20
 **/
@Slf4j
@Configuration
@ConditionalOnProperty(name = "pai4j.log.enabled", havingValue = "true", matchIfMissing = true)
@EnableConfigurationProperties(LogProperties.class)
@Import({LogAsyncConfig.class})
public class LogAutoConfiguration {

    /**
     * 日志服务Bean
     */
    @Bean
    @ConditionalOnMissingBean
    public ILogService logService() {
        log.info("初始化日志服务");
        return new LogServiceImpl();
    }

    /**
     * 日志切面Bean
     */
    @Bean
    @ConditionalOnMissingBean
    public LogAspect logAspect() {
        log.info("初始化日志切面");
        return new LogAspect();
    }
}
